Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeachfrontBidder: fix beachfront bid floor #1334

Merged
merged 3 commits into from
Jul 7, 2021
Merged

Conversation

nickluck9
Copy link

No description provided.

@nickluck9 nickluck9 requested a review from SerhiiNahornyi June 24, 2021 10:28
Copy link
Collaborator

@SerhiiNahornyi SerhiiNahornyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add more unit tests

Comment on lines 249 to 250
extImpBeachfrontBidfloor = extImpBeachfrontBidfloor == null ? ZERO : extImpBeachfrontBidfloor;
impBidfloor = impBidfloor == null ? ZERO : impBidfloor;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create separate variables, and not use method arguments assignments

Comment on lines 248 to 261
private static BigDecimal getBidFloor(BigDecimal extImpBeachfrontBidfloor, BigDecimal impBidfloor) {
extImpBeachfrontBidfloor = extImpBeachfrontBidfloor == null ? ZERO : extImpBeachfrontBidfloor;
impBidfloor = impBidfloor == null ? ZERO : impBidfloor;
final BigDecimal resultFloor;

if (impBidfloor.compareTo(ZERO) > 0) {
resultFloor = impBidfloor;
} else if (extImpBeachfrontBidfloor.compareTo(ZERO) > 0) {
resultFloor = extImpBeachfrontBidfloor;
} else {
resultFloor = MIN_BID_FLOOR;
}

return resultFloor.compareTo(MIN_BID_FLOOR) < 0 ? MIN_BID_FLOOR : resultFloor;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor to something like this

private static BigDecimal getBidFloor(BigDecimal extImpBidfloor, BigDecimal impBidfloor) {
        final BigDecimal impNonNullBidfloor = zeroIfNull(impBidfloor);
        final BigDecimal extImpNonNullBidfloor = zeroIfNull(extImpBidfloor);

        if (impNonNullBidfloor.compareTo(MIN_BID_FLOOR) > 0) {
            return impNonNullBidfloor;
        } else if (extImpNonNullBidfloor.compareTo(MIN_BID_FLOOR) > 0) {
            return extImpNonNullBidfloor;
        } else {
            return ZERO;
        }
    }

    public static BigDecimal zeroIfNull(BigDecimal bigDecimal) {
        return bigDecimal == null ? BigDecimal.ZERO : bigDecimal;
    }

final BigDecimal resultFloor;

if (impBidfloor.compareTo(ZERO) > 0) {
resultFloor = impBidfloor;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add test for this case

@@ -64,6 +64,7 @@
private static final BigDecimal MIN_BID_FLOOR = BigDecimal.valueOf(0.01);
private static final int DEFAULT_VIDEO_WIDTH = 300;
private static final int DEFAULT_VIDEO_HEIGHT = 250;
private static final BigDecimal ZERO = BigDecimal.ZERO;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need it?

@nickluck9 nickluck9 requested a review from SerhiiNahornyi June 30, 2021 13:29
@rpanchyk rpanchyk merged commit 7c91861 into master Jul 7, 2021
@rpanchyk rpanchyk deleted the beachfront_fix_bid_floor branch July 7, 2021 10:51
nickluck9 pushed a commit that referenced this pull request Jul 8, 2021
nickluck9 pushed a commit that referenced this pull request Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants